package cn.huapu.power.energy.service.impl;

import cn.huapu.power.energy.bean.Clientpowerst;
import cn.huapu.power.energy.bean.bo.DateParameterBo;
import cn.huapu.power.energy.bean.vo.ClientpowerstVo;
import cn.huapu.power.energy.mapper.ClientpowerstMapper;
import cn.huapu.power.energy.service.ClientpowerstService;
import cn.huapu.power.energy.util.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;

/**
 * 测试用户权限服务实现类
 * @author autogen
 *
 */
@Service
public class ClientpowerstServiceImpl extends BaseServiceImpl<ClientpowerstMapper, Clientpowerst,Integer> implements ClientpowerstService {

    @Autowired
    private ClientpowerstMapper clienMapper;
    
    @Override
    @Transactional(readOnly = true)
    public List<Double> getElecWeek(DateParameterBo da,String DateTerdaySzy,String DateTerdaySzr) throws ParseException {
        List<Double> cliesWeek = clienMapper.getElecWeek(da.getId(),DateTerdaySzy,DateTerdaySzr);
        return cliesWeek;
    }

    @Override
    @Transactional(readOnly = true)
    public List<ClientpowerstVo> getMonthBuyElec(DateParameterBo da) {
        //获取今年与上一年
    	LocalDate now = LocalDate.now();       
        int yearJn = now.getYear();
        int yearSn = yearJn - 1;
        List<ClientpowerstVo> cliesYear = clienMapper.getWholeCableByYear(da.getId(),yearSn,yearJn);

        List<ClientpowerstVo> cliesMonthSn = clienMapper.getWholeCableByMonth(da.getId(), yearSn);

        List<ClientpowerstVo> cliesMonthJn = clienMapper.getWholeCableByMonth(da.getId(), yearJn);

        if(!ValidateUtil.listIsNull(cliesYear)){
            cliesYear.get(0).setCliesMonth(cliesMonthSn);
            if(cliesYear.size() > 1)
            cliesYear.get(1).setCliesMonth(cliesMonthJn);
        }

        return cliesYear;
    }

    @Override
    @Transactional(readOnly = true)
    public List<ClientpowerstVo> getDayBuyElec(DateParameterBo da) {
        List<ClientpowerstVo> cliesDay = clienMapper.getDayBuyElec(da);
        return cliesDay;
    }
}
